#!/bin/sh
# This regression test is a part of SIPp.
# With -trace_stat, the standard deviation columns of a period with a
# single call are 0, not the garbage a division by zero gave.
. "`dirname "$0"`/../functions"; init

rm -f stat.log
sippbg -sn uas -i 127.0.0.1 -p 27210 -m 1 -timeout 10
sippfg -sn uac -i 127.0.0.1 -p 27211 127.0.0.1:27210 -m 1 \
    -timeout 10 -timeout_error -trace_stat -stf stat.log \
    >/dev/null 2>&1
status=$?

test -s stat.log || fail "no stat.log, sipp exited with $status"
# (it's not a log, it's a csv)
bad=`awk -F';' '
    NR == 1 { for (i = 1; i <= NF; i++) if ($i ~ /StDev/) col[i] = $i; next }
    { for (i in col) if ($i != "00:00:00:000000") print col[i] "=" $i }
' stat.log | sort -u`
calls=`cut -d';' -f16 stat.log | tail -n1`
rm -f stat.log

if test $status -ne 0; then
    fail "UAC failed with $status"
elif test "$calls" != 1; then
    fail "got $calls calls"
elif test -n "$bad"; then
    fail `echo $bad`
else
    ok
fi
